//
// Description: 836. 合并集合
// Created by Loading on 2021/12/26.
//

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 100010;

int father[N]; // 存储每个节点的父节点

// 查找 x 的祖先节点 + 路径压缩
int find(int x) {
    if (father[x] != x) {
        father[x] = find(father[x]);
    }
    return father[x];
}

int main() {
    int n, m;
    cin >> n >> m;
    // 初始化
    for (int i = 1; i <= n; ++i) {
        father[i] = i;
    }
    while (m--) {
        char op;
        int a, b;
        cin >> op >> a >> b;
        if (op == 'M') {
            father[find(a)] = find(b);
        } else {
            if (find(a) == find(b)) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }

    return 0;
}